package com.transactional.controller;

import com.transactional.bean.User;
import com.transactional.service.OuterInvoking;
import com.transactional.service.UserService;
import com.transactional.service.differentclass.Service1;
import com.transactional.service.differentclass.Service2;
import com.transactional.service.innerclass.InnerService1;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Service
@RestController
public class Test {
    @Autowired
    private UserService userService;
    @Autowired
    private Service1 service1;
    @Autowired
    private InnerService1 innerService1;
    @Autowired
    private OuterInvoking outerInvoking;
    private final Logger logger= LoggerFactory.getLogger(Test.class);
    private static int remain = 2000;

    @RequestMapping("/insert")
    public int insert(){
        User user = new User();
        user.setUserName("包华杰");
        user.setPassword("123");
        user.setPhone("234124");
        return userService.insert2(user);
    }

    @RequestMapping("/insert1")
    public int OuterInvoking(){
        outerInvoking.test();
        return 0;
    }

    @RequestMapping("/insert2")
    public int insert2() throws Exception {
        User user = new User();
        user.setUserName("包华杰");
        user.setPassword("123");
        user.setPhone("234124");
        userService.manualController(user);
        return 0;
    }

    @RequestMapping("/demo1")
    public int demo1(@RequestBody User user) throws Exception {
        int i = service1.demo1(user);
        return i;
    }

    @RequestMapping("/innerService1Demo1")
    public int innerService1Demo1(@RequestBody User user) throws Exception {
        int i = innerService1.demo1(user);
        return i;
    }

    @RequestMapping("/innerService1Demo3")
    public int innerService1Demo3(@RequestBody User user) throws Exception {
        int i = innerService1.demo3(user);
        return i;
    }

    @RequestMapping("/demo4")
    public int demo4(@RequestBody User user) throws Exception {
        int i = service1.demo4(user);
        return i;
    }

    @RequestMapping("/multithreadDemo1")
    public int multithreadDemo1(@RequestBody User user) throws Exception {
        int i = service1.multithreadDemo1(user);
        return i;
    }

    @RequestMapping("/afterCommitDemo1")
    public int afterCommitDemo1(@RequestBody User user) throws Exception {
        int i = service1.afterCommitDemo1(user);
        return i;
    }


}
